/* ===========================
   CSS Variables for Theming
   =========================== */
:root {
    /* Colors - Light Theme */
    --color-primary: #0066cc;
    --color-primary-dark: #0052a3;
    --color-primary-light: #3385ff;
    --color-secondary: #00a86b;
    --color-secondary-dark: #008855;
    --color-secondary-light: #00d084;

    --color-success: #00a86b;
    --color-error: #dc3545;
    --color-warning: #ffc107;
    --color-info: #17a2b8;

    --color-background: #f8f9fa;
    --color-surface: #ffffff;
    --color-surface-alt: #f1f3f5;
    --color-text: #212529;
    --color-text-secondary: #6c757d;
    --color-text-muted: #adb5bd;

    --color-border: #dee2e6;
    --color-border-light: #e9ecef;
    --color-border-dark: #ced4da;

    /* Dark theme tab colors */
    --color-tab-bg: #2c3e50;
    --color-tab-hover: #34495e;
    --color-tab-active: var(--color-primary);
    --color-subtab-bg: #34495e;
    --color-subtab-hover: #4a5f7f;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-xxl: 3rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 1rem;
    --radius-pill: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Typography */
    --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-family-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;

    /* Transitions */
    --transition-base: all 0.2s ease-in-out;
    --transition-fast: all 0.15s ease-in-out;
    --transition-slow: all 0.3s ease-in-out;
}

/* Dark Theme */
[data-theme="dark"] {
    --color-background: #1a1d23;
    --color-surface: #22262e;
    --color-surface-alt: #2c3139;
    --color-text: #e9ecef;
    --color-text-secondary: #adb5bd;
    --color-text-muted: #6c757d;

    --color-border: #495057;
    --color-border-light: #3d434d;
    --color-border-dark: #343a40;

    --color-primary: #4dabf7;
    --color-primary-dark: #339af0;
    --color-primary-light: #74c0fc;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* ===========================
   Reset and Base Styles
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--color-background);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===========================
   Layout Components
   =========================== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    padding: var(--spacing-lg) var(--spacing-xl);
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 100;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    margin: 0;
}

.header-controls {
    position: absolute;
    top: 50%;
    right: var(--spacing-xl);
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* Theme Toggle */
.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-pill);
    padding: var(--spacing-xs) var(--spacing-sm);
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition-base);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Status Indicator */
.api-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-md);
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-pill);
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00ff00;
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: #ff4444;
    animation: none;
}

.status-dot.slow {
    background: #ffa500;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===========================
   Tab Navigation
   =========================== */
.top-tab-container {
    background: var(--color-tab-bg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 90;
}

.top-tab-buttons {
    display: flex;
    justify-content: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 2px;
}

/* Multi-row tab layout */
.top-tab-row {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===========================
   Chat: Code blocks, tools, debug
   =========================== */
.code-block-wrapper { position: relative; }
.code-block-wrapper .btn { opacity: 0.85; }
.code-block { font-family: var(--font-family-mono); font-size: 0.9em; background: var(--color-surface-alt); color: var(--color-text); }
.assistant-tools { border-left: 2px solid var(--color-border); padding-left: 8px; margin-top: 6px; }
.assistant-tools-header { font-size: 0.85em; color: var(--color-text-secondary); margin-bottom: 4px; }
.assistant-debug { margin-top: 6px; }
.assistant-debug summary { cursor: pointer; color: var(--color-text-secondary); }
.assistant-debug pre { background: var(--color-surface-alt); padding: 8px; border: 1px solid var(--color-border); border-radius: 4px; overflow: auto; }

/* Basic token colors for lightweight highlighting */

/* ===========================
   Chat Layout and Components (legacy webui)
   =========================== */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: var(--spacing-md);
    align-items: stretch;
}

.chat-sidebar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    height: 100%;
    max-height: 70vh;
    overflow-y: auto;
}
.sidebar-header { display:flex; justify-content:space-between; align-items:center; margin-bottom: var(--spacing-sm); }
.sidebar-actions { display:flex; gap: var(--spacing-sm); }
.sidebar-search { margin-bottom: var(--spacing-sm); }
.sidebar-search input { width: 100%; }
.conversations-list { display:flex; flex-direction:column; gap:6px; }
.conv-item {
    display:flex; flex-direction:column; gap:2px;
    padding:8px; border:1px solid var(--color-border); border-radius:8px;
    background: var(--color-surface-alt); cursor:pointer; transition: var(--transition-fast);
}
.conv-item:hover { box-shadow: var(--shadow-sm); }
.conv-item.active { border-color: var(--color-primary); background: var(--color-background); }
.conv-title { font-weight:600; }
.conv-meta { font-size:0.8em; color: var(--color-text-muted); display:flex; gap:8px; justify-content:space-between; }
.conv-actions { display:flex; gap:6px; }

.chat-main { display:flex; flex-direction:column; gap: var(--spacing-sm); }
.chat-toolbar { display:flex; justify-content:space-between; align-items:flex-end; gap: var(--spacing-md); }
.model-picker { display:flex; align-items:center; gap: var(--spacing-sm); }
.model-picker input { width:200px; }

.system-prompt-row { display:flex; gap: var(--spacing-sm); align-items:center; }
.system-prompt-row textarea { flex:1; min-height:60px; }

.chat-messages {
    position: relative;
    height: 48vh;
    min-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    background: var(--color-surface);
}
.chat-jump-latest {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    padding: 6px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: var(--color-surface-alt);
}

.chat-composer {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    box-shadow: var(--shadow-sm);
}
.composer-row { display:flex; gap: var(--spacing-sm); align-items:flex-start; }
.composer-row textarea { flex:1; min-height:60px; }
.composer-attachments { display:flex; align-items:center; gap: var(--spacing-sm); }
.attach-preview { display:flex; align-items:center; gap:6px; }
.attach-preview img { max-height:40px; border-radius:6px; border:1px solid var(--color-border); }
.composer-hint { color: var(--color-text-muted); font-size: 0.9em; margin: 4px 0; }
.composer-controls { display:flex; align-items:center; justify-content:space-between; gap: var(--spacing-sm); flex-wrap:wrap; }
.composer-meta { display:flex; align-items:center; gap: var(--spacing-sm); margin-top:6px; }

.chat-right { display:flex; flex-direction:column; gap: var(--spacing-sm); }
.chat-right .card { border:1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--spacing-md); background: var(--color-surface); }
.chat-right .card-title { font-weight:600; margin-bottom:6px; }
.tools-log { max-height: 28vh; overflow:auto; }

/* Chat message bubbles */
.chat-message { display:flex; margin-bottom: 8px; }
.chat-message .bubble {
    max-width: 80%;
    padding: 10px 12px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}
.chat-message.user { justify-content: flex-end; }
.chat-message.user .bubble { background: #e3f2fd; }
.chat-message.assistant { justify-content: flex-start; }
.chat-message.assistant .bubble { background: var(--color-surface-alt); }
.chat-message.system { justify-content:center; }
.chat-message.system .bubble { background: #fff3e0; font-style: italic; }

.assistant-answer .collapsible { max-height: 240px; overflow:hidden; position:relative; }
.assistant-answer .gradient-fade { position:absolute; left:0; right:0; bottom:0; height:48px; background: linear-gradient(180deg, rgba(0,0,0,0) 0%, var(--color-surface-alt) 100%); }
.expand-btn { margin-top:6px; }

.message-actions { display:flex; gap:6px; margin-top:6px; }

/* Error banner */
.error-banner {
    border-left: 3px solid var(--color-error);
    background: rgba(220,53,69,0.08);
    padding: 8px;
    border-radius: 6px;
    color: var(--color-error);
}

/* Tool cards (collapsible) */
.tool-call, .tool-result { border-left:3px solid var(--color-border); padding-left:8px; margin:6px 0; }
.tool-card details summary { cursor:pointer; }
.assistant-tools .tool-actions { display:flex; gap:8px; margin-top:6px; }

/* Avatars */
.chat-message .avatar {
    width: 28px; height: 28px; min-width:28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.8rem;
    margin: 0 8px;
    color: #fff;
}
.chat-message .avatar img { width: 18px; height: 18px; display:block; border-radius:50%; }
.chat-message.user .avatar { background: #1f78d1; }
.chat-message.assistant .avatar { background: #6c757d; }
.chat-message.system .avatar { background: #f59f00; }

/* Bubble alignment with avatar */
.chat-message.user .bubble, .chat-message.assistant .bubble, .chat-message.system .bubble {
    display: inline-block;
}

/* Dev-only marker for migrated inline handlers (enable via localStorage.DEV_MIGRATE_MARKERS=1) */
.migrated-inline {
    outline: 1px dashed var(--color-warning);
    outline-offset: 2px;
}
.tok-key { color: #7a7; }
.tok-string { color: #c22; }
.tok-number { color: #164; }
.tok-boolean { color: #07a; }
.tok-null { color: #777; }
.tok-kw { color: #795e26; }
.tok-func { color: #6f42c1; }
.tok-comment { color: #6a737d; font-style: italic; }

.top-tab-row:last-child {
    border-bottom: none;
}

.top-tab-button {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    border: none;
    padding: var(--spacing-sm) var(--spacing-lg);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
    min-width: 80px;
}

.top-tab-button::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 3px;
    background: var(--color-primary-light);
    transform: translateX(-50%);
    transition: width 0.3s ease;
}

.top-tab-button:hover {
    background: var(--color-tab-hover);
    color: white;
}

.top-tab-button.active {
    background: var(--color-tab-active);
    color: white;
}

.top-tab-button.active::before {
    width: 100%;
}

/* Sub-tabs */
.sub-tab-row {
    background: var(--color-subtab-bg);
    display: none;
    border-bottom: 1px solid var(--color-border-dark);
}

.sub-tab-row.active {
    display: block;
}

.sub-tab-buttons {
    display: flex;
    justify-content: center;
    padding: 0;
    margin: 0;
    gap: 1px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.sub-tab-buttons::-webkit-scrollbar {
    height: 6px;
}

.sub-tab-buttons::-webkit-scrollbar-track {
    background: transparent;
}

.sub-tab-buttons::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-pill);
}

.sub-tab-button {
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    border: none;
    padding: var(--spacing-sm) var(--spacing-lg);
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: var(--transition-fast);
}

.sub-tab-button:hover {
    background: var(--color-subtab-hover);
    color: white;
}

.sub-tab-button.active {
    background: var(--color-primary);
    color: white;
}

/* ===========================
   Content Area
   =========================== */
.content-container {
    flex: 1;
    padding: var(--spacing-xl);
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===========================
   Endpoint Sections
   =========================== */
.endpoint-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    margin-bottom: var(--spacing-xl);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.endpoint-section:hover {
    box-shadow: var(--shadow-md);
}

.endpoint-section h2 {
    color: var(--color-primary);
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 var(--spacing-lg) 0;
    padding-bottom: var(--spacing-md);
    border-bottom: 2px solid var(--color-border-light);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.endpoint-method {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.endpoint-method.get { background: #28a745; color: white; }
.endpoint-method.post { background: #007bff; color: white; }
.endpoint-method.put { background: #ffc107; color: #000; }
.endpoint-method.delete { background: #dc3545; color: white; }
.endpoint-method.patch { background: #6c757d; color: white; }

.endpoint-path {
    font-family: var(--font-family-mono);
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* ===========================
   Form Elements
   =========================== */
.form-group {
    margin-bottom: var(--spacing-lg);
}

label {
    display: block;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--spacing-sm);
    font-size: 0.9rem;
}

/* Keep checkbox label text on same line as the checkbox for ingestion forms */
.form-group input[type="checkbox"] + label,
.checkbox-inline label {
    display: inline-flex;
    align-items: center;
    margin: 0 0 0 6px; /* left gap only */
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    color: var(--color-text);
    transition: var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

input:invalid,
textarea:invalid {
    border-color: var(--color-error);
}

input:invalid:focus,
textarea:invalid:focus {
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

textarea {
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}

textarea.code-input {
    font-family: var(--font-family-mono);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* File Input */
.file-input-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.file-input-wrapper > input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    background: var(--color-surface-alt);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

.file-input-label:hover {
    background: var(--color-surface);
    border-color: var(--color-primary);
}

.file-input-wrapper.has-file .file-input-label {
    border-style: solid;
    border-color: var(--color-success);
    background: rgba(0, 168, 107, 0.05);
}

/* Disabled inputs: clearer visual state */
input[disabled],
button[disabled],
select[disabled],
textarea[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(20%);
}

/* Dim the visible file input label when the hidden file input is disabled */
input[type="file"][disabled] + .file-input-label {
    opacity: 0.6;
    cursor: not-allowed;
    border-color: var(--color-border-dark);
}

/* Checkboxes and Radio Buttons */
.checkbox-group,
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

/* Stack checkboxes vertically in processing endpoints */
#tabMediaProcessingNoDB .checkbox-group,
.endpoint-section .checkbox-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    align-items: flex-start;
}

.checkbox-wrapper,
.radio-wrapper {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

input[type="checkbox"],
input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-border);
    transition: var(--transition-fast);
    border-radius: var(--radius-pill);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: var(--transition-fast);
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background: var(--color-primary);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface);
    border-color: var(--color-border-dark);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #008855;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-danger {
    background: var(--color-error);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c82333;
}

.btn-sm {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.875rem;
}

.btn-lg {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: 1.1rem;
}

.btn-icon {
    padding: var(--spacing-sm);
    width: 36px;
    height: 36px;
}

.btn-group {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

/* API Button (legacy compatibility) */
.api-button {
    background: var(--color-success);
    color: white;
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition-fast);
    margin-top: var(--spacing-md);
}

.api-button:hover {
    background: #008855;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ===========================
   Response Display
   =========================== */
.response-section {
    margin-top: var(--spacing-xl);
}

.response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

.response-header h3 {
    color: var(--color-text);
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.response-controls {
    display: flex;
    gap: var(--spacing-sm);
}

pre {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    font-family: var(--font-family-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 500px;
    position: relative;
}

pre.response-content {
    background: #1e1e1e;
    color: #d4d4d4;
}

/* Compact button variant used in dense tables */
.btn-compact {
    padding: 2px 6px;
    font-size: 0.8rem;
}

/* Strong focus indication for keyboard users */
.btn:focus-visible,
.api-button:focus-visible,
.top-tab-button:focus-visible,
.sub-tab-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===========================
   RBAC Tables & Utilities
   =========================== */
.rbac-sticky-left { position: sticky; left: 0; background: var(--color-surface); z-index: 2; }
.rbac-sticky-left.header { z-index: 3; }
.small-table th, .small-table td { white-space: nowrap; }
.scroll-x { overflow-x: auto; }
.scroll-y { overflow-y: auto; }
/* Generic spinner (used in RBAC views) */
.spinner {
    width: 36px;
    height: 36px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: rgba(255,255,255,0.8);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 8px auto;
}

/* Mobile: allow horizontal scrolling for crowded top tab rows */
@media (max-width: 768px) {
    .top-tab-row {
        overflow-x: auto;
    }
    .top-tab-buttons {
        justify-content: flex-start;
    }
}

.copy-button {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-fast);
}

pre:hover .copy-button {
    opacity: 1;
}

.copy-button:hover {
    background: var(--color-primary-dark);
}

/* ===========================
   Validation Helpers
   =========================== */
.input-invalid {
    border-color: var(--color-error) !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.12);
}

.validation-summary {
    margin: 8px 0 12px 0;
    padding: 8px 10px;
    background: rgba(220, 53, 69, 0.06);
    border-left: 3px solid var(--color-error);
    color: var(--color-error);
    border-radius: var(--radius-sm);
    display: none;
}

.validation-summary.visible {
    display: block;
}

.field-hint {
    display: block;
    margin-top: 4px;
    color: var(--color-text-muted);
}

.field-hint.error {
    color: var(--color-error);
}

/* ===========================
   Simple Charts (no external deps)
   =========================== */
.chart-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    min-height: 220px;
    box-shadow: var(--shadow-sm);
}

.chart-placeholder {
    width: 100%;
    height: 100%;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    height: 160px;
    padding: var(--spacing-md) var(--spacing-sm);
}

.chart-bar {
    flex: 1 1 40px;
    min-width: 28px;
    max-width: 80px;
    background: linear-gradient(180deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.chart-bar:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.chart-bar-label {
    position: absolute;
    bottom: -1.5rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    text-align: center;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-bar-value {
    position: absolute;
    top: -1.25rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--color-surface);
    color: var(--color-text);
    padding: 2px 6px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
}

/* Dark theme modifiers */
[data-theme="dark"] .chart-container {
    background: var(--color-surface-alt);
    border-color: var(--color-border-dark);
}

[data-theme="dark"] .chart-bar-value {
    background: var(--color-surface);
}

/* Responsive: stack bars tighter on small screens */
@media (max-width: 768px) {
    .chart-bars { gap: 6px; height: 140px; }
    .chart-bar { min-width: 22px; }
    .chart-bar-label { bottom: -1.25rem; font-size: 0.7rem; }
    .chart-bar-value { top: -1rem; font-size: 0.7rem; }
}

/* Legend and Tooltip */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border-light);
    font-size: 0.8rem;
}

.legend-item.disabled {
    opacity: 0.5;
    text-decoration: line-through;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid var(--color-border);
}

.chart-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 0.8rem;
    box-shadow: var(--shadow-sm);
    z-index: 10000;
    display: none;
}

/* ===========================
   Chat UI Specific
   =========================== */
.message-entry {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    position: relative;
    transition: var(--transition-fast);
}

.message-entry:hover {
    box-shadow: var(--shadow-sm);
}

.message-role-badge {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: var(--spacing-sm);
}

.message-role-badge.system { background: #6c757d; color: white; }
.message-role-badge.user { background: #007bff; color: white; }
.message-role-badge.assistant { background: #28a745; color: white; }
.message-role-badge.tool { background: #ffc107; color: #000; }

.message-content-area {
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.message-image-preview {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-md);
    margin-top: var(--spacing-sm);
    box-shadow: var(--shadow-sm);
}

.add-message-btn {
    background: var(--color-info);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.add-message-btn:hover {
    background: #138496;
    transform: translateY(-1px);
}

.remove-message-btn {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    background: var(--color-error);
    color: white;
    border: none;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition-fast);
}

.remove-message-btn:hover {
    background: #c82333;
}

/* ===========================
   Optional Parameters Section
   =========================== */
.optional-params {
    background: var(--color-surface-alt);
    border-left: 3px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-top: var(--spacing-xl);
}

.optional-params-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    cursor: pointer;
    user-select: none;
}

.optional-params-header h3 {
    color: var(--color-text);
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.optional-params-toggle {
    transition: transform 0.3s ease;
}

.optional-params.collapsed .optional-params-content {
    display: none;
}

.optional-params.collapsed .optional-params-toggle {
    transform: rotate(-90deg);
}

/* ===========================
   Loading States
   =========================== */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    z-index: 10;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(0, 0, 0, 0.7);
}

/* ===========================
   Toast Notifications
   =========================== */
.toast-container {
    position: fixed;
    top: var(--spacing-xl);
    right: var(--spacing-xl);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.toast {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--spacing-md) var(--spacing-lg);
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 500px;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--color-success);
}

.toast.error {
    border-left: 4px solid var(--color-error);
}

.toast.warning {
    border-left: 4px solid var(--color-warning);
}

.toast.info {
    border-left: 4px solid var(--color-info);
}

.toast-icon {
    font-size: 1.5rem;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.toast-message {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.toast-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    transition: var(--transition-fast);
}

.toast-close:hover {
    color: var(--color-text);
}

/* ===========================
   Utility Classes
   =========================== */
.columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
}

/* Simple Landing: stack quick actions vertically for more space */
#tabSimpleLanding > .columns {
    grid-template-columns: 1fr;
}

.hidden {
    display: none !important;
}

.text-muted {
    color: var(--color-text-muted);
}

.text-small {
    font-size: 0.875rem;
}

.text-mono {
    font-family: var(--font-family-mono);
}

.mt-1 { margin-top: var(--spacing-sm); }
.mt-2 { margin-top: var(--spacing-md); }
.mt-3 { margin-top: var(--spacing-lg); }
.mt-4 { margin-top: var(--spacing-xl); }

.mb-1 { margin-bottom: var(--spacing-sm); }
.mb-2 { margin-bottom: var(--spacing-md); }
.mb-3 { margin-bottom: var(--spacing-lg); }
.mb-4 { margin-bottom: var(--spacing-xl); }

.p-1 { padding: var(--spacing-sm); }
.p-2 { padding: var(--spacing-md); }
.p-3 { padding: var(--spacing-lg); }
.p-4 { padding: var(--spacing-xl); }

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    header {
        padding: var(--spacing-md);
    }

    header h1 {
        font-size: 1.5rem;
    }

    .header-controls {
        position: static;
        transform: none;
        margin-top: var(--spacing-md);
        justify-content: center;
    }

    .content-container {
        padding: var(--spacing-md);
    }

    .columns {
        grid-template-columns: 1fr;
    }

    .top-tab-buttons {
        overflow-x: auto;
        justify-content: flex-start;
    }

    .top-tab-row {
        overflow-x: auto;
        justify-content: flex-start;
        flex-wrap: nowrap;
        padding: 2px 0;
    }

    .top-tab-button {
        font-size: 0.85rem;
        padding: var(--spacing-xs) var(--spacing-md);
        min-width: 70px;
    }

    .toast-container {
        top: var(--spacing-md);
        right: var(--spacing-md);
        left: var(--spacing-md);
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }
}

/* ===========================
   Accessibility
   =========================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: var(--spacing-sm) var(--spacing-md);
    text-decoration: none;
    z-index: 1001;
}

.skip-link:focus {
    top: 0;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --color-border: #000;
        --shadow-sm: 0 0 0 1px #000;
        --shadow-md: 0 0 0 2px #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Media Analysis Tab Styles */
#tabMediaAnalysis .search-section {
    margin-bottom: 20px;
}

/* Media List Container */
.media-list-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    background: var(--bg-secondary);
}

.media-list-item {
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-primary);
}

.media-list-item:hover {
    border-color: var(--color-primary);
    background: rgba(0, 123, 255, 0.05);
    transform: translateX(5px);
}

.media-list-item:last-child {
    margin-bottom: 0;
}

.media-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xs);
}

.media-item-header h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.media-type-badge {
    background: var(--color-primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.media-list-item .item-author {
    margin: var(--spacing-xs) 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.media-list-item .item-date {
    margin: var(--spacing-xs) 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Pagination Controls */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.pagination-controls button {
    min-width: 80px;
}

.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 200px;
    text-align: center;
}

#tabMediaAnalysis .search-result-item {
    padding: 12px;
    border: 1px solid var(--color-border);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#tabMediaAnalysis .search-result-item:hover {
    background-color: var(--color-input-bg);
}

#tabMediaAnalysis .search-result-item h4 {
    margin: 0 0 8px 0;
    color: var(--color-primary);
}

#tabMediaAnalysis .search-result-item .item-type {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    margin: 4px 0;
}

#tabMediaAnalysis .search-result-item .item-author {
    font-size: 0.9em;
    font-style: italic;
    margin: 4px 0;
}

#tabMediaAnalysis .search-result-item .item-description {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    margin: 8px 0 0 0;
}

#tabMediaAnalysis .selected-media-card {
    padding: 16px;
    background: var(--color-input-bg);
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    margin-bottom: 20px;
}

#tabMediaAnalysis .selected-media-card h3 {
    margin-top: 0;
    color: var(--color-primary);
}

#tabMediaAnalysis .prompt-section {
    margin: 20px 0;
}

#tabMediaAnalysis .prompt-source-toggle {
    margin-bottom: 16px;
}

#tabMediaAnalysis .prompt-source-toggle label {
    margin-right: 20px;
}

#tabMediaAnalysis textarea {
    width: 100%;
    min-height: 100px;
    padding: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-input-bg);
    color: var(--color-text);
    font-family: inherit;
    resize: vertical;
}

#tabMediaAnalysis .model-params {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 20px 0;
}

#tabMediaAnalysis .param-group {
    display: flex;
    flex-direction: column;
}

#tabMediaAnalysis .param-group label {
    margin-bottom: 8px;
}

#tabMediaAnalysis .param-group input[type="range"] {
    width: 100%;
}

#tabMediaAnalysis .analysis-result {
    padding: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin: 20px 0;
}

#tabMediaAnalysis .analysis-result .result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

#tabMediaAnalysis .analysis-result .timestamp {
    font-size: 0.9em;
    color: var(--color-text-secondary);
}

#tabMediaAnalysis .analysis-result .result-content {
    line-height: 1.6;
}

#tabMediaAnalysis .streaming-output {
    padding: 12px;
    background: var(--color-input-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    min-height: 100px;
    white-space: pre-wrap;
    font-family: monospace;
}

#tabMediaAnalysis .analysis-card {
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-bottom: 12px;
}

#tabMediaAnalysis .analysis-card .analysis-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

#tabMediaAnalysis .analysis-card h4 {
    margin: 0;
    color: var(--color-primary);
}

#tabMediaAnalysis .analysis-card .analysis-date {
    font-size: 0.9em;
    color: var(--color-text-secondary);
}

#tabMediaAnalysis .analysis-card .analysis-preview {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    margin: 8px 0;
}

#tabMediaAnalysis .analysis-card .analysis-actions {
    display: flex;
    gap: 8px;
}

#tabMediaAnalysis .btn-small {
    padding: 4px 12px;
    font-size: 0.9em;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

#tabMediaAnalysis .btn-small:hover {
    opacity: 0.9;
}

#tabMediaAnalysis .btn-danger {
    background: #d32f2f;
}

#tabMediaAnalysis .loading {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 20px;
}

#tabMediaAnalysis .error {
    color: #d32f2f;
    padding: 12px;
    background: rgba(211, 47, 47, 0.1);
    border: 1px solid #d32f2f;
    border-radius: 4px;
}

#tabMediaAnalysis .no-results,
#tabMediaAnalysis .no-analyses {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 20px;
    font-style: italic;
}
/* Flashcards tag chips */
.fc-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.fc-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid var(--color-border); border-radius: var(--radius-pill); background: var(--color-surface); font-size: 0.9em; }
.fc-chip .fc-chip-x { border: none; background: transparent; color: var(--color-text-secondary); cursor: pointer; padding: 0 2px; font-size: 1em; line-height: 1; }
.fc-chip .fc-chip-x:hover { color: var(--color-text); }
.fc-tag-input { min-width: 80px; border: 1px solid var(--color-border); padding: 2px 6px; border-radius: var(--radius-sm); }
/* Collapsible Sections */
.collapsible-header { display:flex; align-items:center; justify-content:space-between; gap: 8px; cursor: pointer; }
.collapsible-header h3 { display:inline-block; margin: 0; }
.collapsible-body { margin-top: 8px; }

/* Collapsible toggle button visual when used as a separate control */
.collapsible-toggle-btn { margin-left: auto; }

/* Simple progress bar (already styled inline in HTML) */
.progress-container { position: relative; }
.progress-bar { transition: width 0.2s ease; }

/* ===========================
   Moderation Lint Badges
   =========================== */
.lint-ok {
    color: var(--color-success);
    font-weight: 600;
}
.lint-invalid {
    color: var(--color-error);
    font-weight: 600;
}
.lint-icon { margin-right: 6px; }
/* ===========================
   Disabled Controls Styling
   =========================== */
input[disabled],
select[disabled],
textarea[disabled],
button[disabled],
.form-control[disabled],
.form-control-file[disabled] {
    opacity: 0.55;
    cursor: not-allowed !important;
    filter: grayscale(30%);
}

.file-upload-area[aria-disabled="true"],
.file-upload-area.disabled {
    opacity: 0.55;
    cursor: not-allowed !important;
    pointer-events: none;
}
